package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.domain.mongo.Movement;
import org.apache.commons.io.filefilter.MagicNumberFileFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.GET;
import java.io.IOException;
import java.util.Map;

@RestController
public class MovementController {

    @Autowired
    private MovementManager movementManager;

    @PostMapping("/movements")
    public void saveMovementManager(Movement movement, MultipartFile[] multipartFile) throws IOException {

        movementManager.saveMovementManager(movement, multipartFile);
    }

    @GetMapping("/movements/all")
    public ResponseEntity findMyMovementByPage(
            Long userId,
            @RequestParam(defaultValue = "1", value = "page") Integer pageNum,
            @RequestParam(defaultValue = "10", value = "pagesize") Integer pageSize
    ) {

        return movementManager.findMyMovementByPage(userId, pageNum, pageSize);
    }

    @GetMapping("/movements")
    public ResponseEntity findFriendMovementByPage(
            @RequestParam(defaultValue = "1", value = "page") Integer pageNum,
            @RequestParam(defaultValue = "10", value = "pagesize") Integer pageSize) {

        return movementManager.findFriendMovementByPage(pageNum, pageSize);
    }

    /*@GetMapping("/movements/recommend")
    public ResponseEntity findRecommendMovementByPage(
            @RequestParam(defaultValue = "1", value = "page") Integer pageNum,
            @RequestParam(defaultValue = "10", value = "pagesize") Integer pageSize
    ) {

        return movementManager.findRecommendMovementByPage(pageNum, pageSize);
    }*/

    @GetMapping("/movements/recommend")
    public ResponseEntity findRecommendMovementByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return movementManager.findRecommendMovementByPage(pageNum, pageSize);
    }

    @GetMapping("/movements/{publishId}/like")
    public ResponseEntity movementLike(@PathVariable String publishId) {

        return movementManager.movementLike(publishId);
    }

    @GetMapping("/movements/{publishId}/dislike")
    public ResponseEntity movementDislike(@PathVariable String publishId) {
        // 调用manager
        return movementManager.movementDislike(publishId);
    }

    @GetMapping("/movements/{publishId}/love")
    public ResponseEntity movementLove(@PathVariable String publishId) {

        return movementManager.movementLove(publishId);
    }

    @GetMapping("/movements/{publishId}/unlove")
    public ResponseEntity movementUnlove(@PathVariable String publishId) {

        return movementManager.movementUnlove(publishId);
    }

   /* @GetMapping("/comments")
    public ResponseEntity findCommentVoByPage(
            @RequestParam(value = "movementId") String publishId,
            @RequestParam(defaultValue = "1", value = "page") Integer pageNum,
            @RequestParam(defaultValue = "10", value = "pagesize") Integer pageSize
    ) {

        System.out.println("评论信息显示");

        return movementManager.findCommentVoByPage(publishId, pageNum, pageSize);
    }*/
   @GetMapping("/comments")
   public ResponseEntity findCommentVoByPage(
           @RequestParam(value = "movementId") String publishId,
           @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
           @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
       // 调用manager

       System.out.println("发表品论");
       return movementManager.findCommentVoByPage(publishId, pageNum, pageSize);
   }

    @PostMapping("/comments")
    public void movementComment(@RequestParam Map<String, String> param) {

        String publishId = param.get("movementId");

        String content = param.get("comment");

        System.out.println("发表评论");

        movementManager.movementComment(publishId, content);
    }
}
